package com.sdry.system.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdry.system.entity.PostUser;
import com.sdry.system.entity.RoleUser;
import com.sdry.system.entity.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @version: 1.0
 * @description: 用户管理
 * @author: cb
 * @create: 2020-01-13 20:18
 **/
public interface UserMapper extends BaseMapper<SysUser> {


    /**
     * 角色用户添加
     * @param roleId
     * @param userId
     * @return
     */
    @Insert("insert into sys_role_user(role_id,user_id) VALUES (#{roleId},#{userId})")
    Integer addRoleUser(@Param("roleId") String roleId, @Param("userId") Long userId);

    /**
     * 根据ID查询用户角色
     * @param userId
     * @return
     */
    @Select("select role_id,user_id from sys_role_user where user_id = #{userId} ")
    List<RoleUser> queryRoleUserByUserIdList(Long userId);

    /**
     * 添加员工
     * @param pId
     * @param userId
     * @return
     */
    @Insert("insert into sys_post_user(post_id,user_id) VALUES (#{pId},#{userId})")
    Integer addPostUser(@Param("pId") String pId, @Param("userId") Long userId);

    /**
     * 岗位用户表
     * @param userId
     * @return
     */
    @Select("select post_id,user_id from sys_post_user where user_id = #{userId}")
    List<PostUser> queryPostUser(Long userId);

    /**
     * 删除员工职位表
     * @param userId
     * @return
     */
    @Delete("delete from sys_post_user where  user_id = #{userId}")
    Integer deletePostUser(@Param("userId") Long userId);

    /**
     * 删除员工用户
     * @param userId
     * @return
     */
    Integer updateUserStatus(Long userId);

    /**
     * 删除角色用户
     * @param userId
     * @return
     */
    @Delete("delete from sys_role_user where user_id = #{userId}")
    Integer deleteRoleUser(Long userId);

    /**
     * 修改密码
     * @param userId 用户ID
     * @param newPad 新密码
     * @return Integer
     */
    @Update("update sys_user set password = #{newPad},update_date = getDate(),update_by = #{userId} where user_id = #{userId}")
    Integer updatePaw(@Param("userId") Long userId, @Param("newPad") String newPad);
}
